From: Daniel Boles Date: Mon, 4 Sep 2017 18:56:47 +0000 (+0100) Subject: EmojiChooser: Ensure always have a selected button X-Git-Tag: archive/raspbian/3.24.39-1+rpi1~1^2~65^2~39^2~213 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=721094529263272f2737dc0e811195edd2df7426;p=gtk%2B3.0.git EmojiChooser: Ensure always have a selected button We were only selecting a section’s button if the adjustment y coord was within its heading, so scrolling slightly into it unchecked all buttons. This also fixes how we could end up with the first 2 selected, somehow. https://bugzilla.gnome.org/show_bug.cgi?id=787172 --- diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c index 7d8c589a04..3f74f576af 100644 --- a/gtk/gtkemojichooser.c +++ b/gtk/gtkemojichooser.c @@ -404,38 +404,54 @@ populate_emoji_chooser (GtkEmojiChooser *chooser) g_bytes_unref (bytes); } -static void -update_state (EmojiSection *section, - double value) -{ - GtkAllocation alloc = { 0, 0, 0, 20 }; - - if (section->heading) - gtk_widget_get_allocation (section->heading, &alloc); - - if (alloc.y <= value && value < alloc.y + alloc.height) - gtk_widget_set_state_flags (section->button, GTK_STATE_FLAG_CHECKED, FALSE); - else - gtk_widget_unset_state_flags (section->button, GTK_STATE_FLAG_CHECKED); -} - static void adj_value_changed (GtkAdjustment *adj, gpointer data) { GtkEmojiChooser *chooser = data; double value = gtk_adjustment_get_value (adj); + EmojiSection const *sections[] = { + &chooser->recent, + &chooser->people, + &chooser->body, + &chooser->nature, + &chooser->food, + &chooser->travel, + &chooser->activities, + &chooser->objects, + &chooser->symbols, + &chooser->flags, + }; + EmojiSection const *select_section = sections[0]; + gsize i; + + /* Figure out which section the current scroll position is within */ + for (i = 0; i < G_N_ELEMENTS (sections); ++i) + { + EmojiSection const *section = sections[i]; + GtkAllocation alloc; - update_state (&chooser->recent, value); - update_state (&chooser->people, value); - update_state (&chooser->body, value); - update_state (&chooser->nature, value); - update_state (&chooser->food, value); - update_state (&chooser->travel, value); - update_state (&chooser->activities, value); - update_state (&chooser->objects, value); - update_state (&chooser->symbols, value); - update_state (&chooser->flags, value); + if (section->heading) + gtk_widget_get_allocation (section->heading, &alloc); + else + gtk_widget_get_allocation (section->box, &alloc); + + if (value < alloc.y) + break; + + select_section = section; + } + + /* Un/Check the section buttons accordingly */ + for (i = 0; i < G_N_ELEMENTS (sections); ++i) + { + EmojiSection const *section = sections[i]; + + if (section == select_section) + gtk_widget_set_state_flags (section->button, GTK_STATE_FLAG_CHECKED, FALSE); + else + gtk_widget_unset_state_flags (section->button, GTK_STATE_FLAG_CHECKED); + } } static gboolean